#!/usr/bin/env bash
set -euxo pipefail

BUILD_TYPE=${1:-debug}
if [ "$BUILD_TYPE" == "qa" ]; then
	echo "Building iOS App in QA mode"
	CONFIGURATION="QA"
else
	echo "Building iOS App in Debug mode"
	CONFIGURATION="Debug"
fi

xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -configuration "$CONFIGURATION" -sdk iphonesimulator build -destination platform="$DEVICE_HOST_PLAT",OS="$DEVICE_HOST_OS",name="$DEVICE_HOST_NAME" -derivedDataPath "$DERIVED_DATA_PATH" ONLY_ACTIVE_ARCH=YES GCC_PREPROCESSOR_DEFINITIONS='$(inherited)' |
	tee ./xcode_build_raw.log |
	bundle exec xcpretty -c

if [ "$BUILD_TYPE" == "qa" ]; then
	echo "Uploading iOS App for QA"
	./scripts/ci/upload-sim-app
fi